// 引入 gis模块 方法
import {
  getAttributeRespnse,
  getBounding,
  getAllBoundary,
  getDataAnalysis,
  saveAccountAttributeTable,
  queryAccountAttributeTable,
  getBusinessRespnse
} from '@/apis/gis'
import api from '@/apis/index'

// 引入 gis方法
import {
  changeMap,
  compareFn,
  getGridBoundary,
  getLonAndAz,
  getLocateCell,
  getAllBoundaryNoClick,
  delGisCommunity,
  getStations,
  bigGridContrast,
  zoomToBigGrid,
  setBoundary,
  clearBoundary,
  getAllBoundaryHaveClick,
  locateArea
} from '@/utils/gisObjFun.js'

import { Message } from 'element-ui'
let pageNum1 = 0
// 查询 网格&热力&小区 图层
function queryBoundary(
  that,
  network,
  mnc,
  ptMonth,
  day,
  type,
  currentStatus,
  ifCommunity = false,
  pageNum
) {
  if (
    that.state.gisPage.gisObj !== null &&
    that.state.gisPage.iframeUrl === 'index'
  ) {
    function getData(formData, gridData, status, boundary) {
      that.dispatch('gisPage/changeBoundaryList', {
        data: null,
        oldFormData: formData,
        gridData,
        oldStatus: status,
        boundary
      }).then(()=>{
          if(pageNum1<10){
            pageNum1++ 
            console.log(pageNum1)
            // queryBoundary(that,
            //   network,
            //   mnc,
            //   ptMonth,
            //   day,
            //   type,
            //   currentStatus,
            //   ifCommunity = false,
            //   pageNum1)

            getGridBoundary(
              formData,
              boundaryList,
              currentStatus,
              gisObj,
              boundary,
              getData,
              ifCommunity,
              pageNum1
            )
          }
      })
    }


    let cityId = that.state.home.userInfoVo.cityId
    let roleType = that.state.home.userInfoVo.roleType
    let formData = {
      cityId,
      mnc,
      ptMonth,
      zoneId: that.state.gisForm.zoneId,
      network,
      userLineId: that.state.gisPage.userLineId,
      roleType
    }
    let boundaryList = that.state.gisPage.boundaryList
    let gisObj = that.state.gisPage.gisObj
    let state = that.state.gisForm
    let boundary = that.state.gisPage.dictionary.find(
      v => v.id == that.state.home.userInfoVo.cityId
    )
    const { routeAreaType } = that.state.gisForm
    if (routeAreaType == 5) {
      formData['day'] = day
      formData['type'] = type
      formData['routeAreaType'] = routeAreaType
      const { zoneId, townId } = that.state.gisForm
      if (zoneId != null && zoneId !== '全部') {
        formData['zoneId'] = zoneId
      }
      if (townId != null && townId !== '全部') {
        formData['townId'] = townId
      }
      boundaryList = []
    }
    if (state.zoneId !== cityId && state.companyId === null) {
      let label = 'zoneId'
      if (state.townId !== '全部' && state.townId !== null) {
        label = 'townId'
      }
      queryAloneArea(that, state, label, state[label]).then(data => {
        getGridBoundary(
          formData,
          boundaryList,
          currentStatus,
          gisObj,
          data,
          getData,
          ifCommunity,
          pageNum1
        )
      })
    } else if (state.companyId !== cityId && state.zoneId === null) {
      let label = 'companyId'
      if (
        state.networkGridId !== '全部' &&
        state.networkGridId !== null &&
        state.microGridId == '全部'
      ) {
        label = 'networkGridId'
      } else if (state.microGridId != null) {
        label = 'microGridId'
      }
      console.log(label)
      queryAloneArea(that, state, label, state[label]).then(data => {
        getGridBoundary(
          formData,
          boundaryList,
          currentStatus,
          gisObj,
          data,
          getData,
          ifCommunity,
          pageNum1
        )
      })
    } else {
      getGridBoundary(
        formData,
        boundaryList,
        currentStatus,
        gisObj,
        boundary,
        getData,
        ifCommunity,
        pageNum1
      )
    }
  }
}

// 遍历添加小区图层
function queryCommunity(arr, that) {
  arr.forEach(item => {
    queryBoundary(
      that,
      item,
      that.state.gisForm.mnc,
      that.state.gisForm.ptMonth,
      that.state.gisForm.day,
      that.state.gisForm.type,
      1,
      true
    )
  })
}

// 遍历添加/删除 车站营业厅图层
function queryCustom(arr, type, that) {
  arr.forEach(item => {
    getStations(item, type, that)
  })
}

// 查询 经纬度 或方位角图层
function queryLonAndAz(that, state) {
  if (
    that.state.gisPage.gisObj !== null &&
    that.state.gisPage.iframeUrl !== 'index'
  ) {
    function getData(data) {
      let str =
        'gisForm/' + (state.perspective == 1 ? 'setLonList' : 'setAzList')
      that.commit(str, data)
    }
    let formData = {
      cityId: that.state.home.userInfoVo.cityId,
      mnc: state.mnc,
      ptMonth: state.ptMonth,
      perspective: state.perspective,
      stateType: state.stateType,
      longitudeType: state.longitudeType,
      azimuthType: state.azimuthType,
      sortType: state.lonAndAzSortType
    }
    let gisObj = that.state.gisPage.gisObj
    getLonAndAz(formData, gisObj, getData)
  }
}

// 查询 大栅格图层
function queryBigGrid(that, state) {
  if (that.state.gisPage.gisObj !== null) {
    function getData(data) {
      that.commit('gisForm/setOffsetCoverageList', data)
    }
    let formData = {
      cityId: that.state.home.userInfoVo.cityId,
      ptMonth: state.ptMonth,
      network: state.network,
      offset: state.offset,
      offsetSort: state.offsetSort
    }
    let gisObj = that.state.gisPage.gisObj
    bigGridContrast(formData, gisObj, getData)
  }
}

// 查询两个数组中不重复的值 （长度相同的数组的不同值 返回空数组）
function getNoRepeatList(arr1, arr2) {
  let maxList = arr1.length > arr2.length ? arr1 : arr2
  let minList = arr1.length < arr2.length ? arr1 : arr2
  let arr3 = []

  for (let i in maxList) {
    let a = maxList[i]
    let count = 0
    for (let j in minList) {
      if (minList[j] == a) {
        count++
      }
    }
    if (count == 0) {
      arr3.push(a)
    }
  }

  return arr3
}

// 查询 单独区域边界 并且 跳转
async function queryLocateArea(that, state, label, value) {
  if (that.state.gisPage.gisObj !== null) {
    queryAloneArea(that, state, label, value).then(data => {
      let gisObj = that.state.gisPage.gisObj
      setBoundary(data, gisObj)
    })
  }
}

// 查询单独区域边界
async function queryAloneArea(that, state, label, value) {
  let params = {
    cityId: that.state.home.userInfoVo.cityId,
    mnc: state.mnc,
    ptMonth: state.ptMonth,
    [label]: value
  }
  let { data = '' } = await getBounding(params)
  return data
}

// 绘制 场景 多边界
function queryAllBoundaryHaveClick(that, state) {
  if (that.state.gisPage.gisObj !== null) {
    let cityId = that.state.home.userInfoVo.cityId
    let formData = {}
    if (state.networkGridId !== null) {
      formData = {
        cityId,
        areaType: state.areaType,
        networkGridId: state.networkGridId,
        microGridId: state.microGridId
      }
    } else {
      formData = {
        cityId,
        areaType: state.areaType,
        zoneId: state.zoneId,
        townId: state.townId
      }
    }

    let gisObj = that.state.gisPage.gisObj
    formData.ptMonth = state.ptMonth
    getAllBoundaryHaveClick(formData, gisObj)
  }
}

const state = {
  // 筛选项

  routeType: 1, //用户： 1， 网络：2 其他: null
  routeAreaType: null, // 用户分析:1, 网络优化:2 ,场景: 3 ，  商机:4 ,
  showLayer: false, // 显示图层 true/false
  layerBoxTop: 185, //图层的top高度
  mnc: null, //运营商 0:移动, 1:联通， 11：电信

  //  1+4':4G网络覆盖,'1+5' :5G网络覆盖,'4+4':4G网络质量,'4+5':5G网络质量
  // '3+4':4G用户分布,'3+5':5G用户分布,'5+4':4G漫入用户分布,'5+5':5G漫入用户分布
  network: '3+',
  ptMonth: null, //月份
  zoneId: null, //区域
  townId: null, //街道id
  companyId: null,
  networkGridId: null, //网格
  microGridId: null, //微格
  keyWord: null, // 搜索词

  // 右侧表格搜索词表格id
  userLineId: null,

  userAnalysisType: null, //用户分析类型

  areaType: null, //场景类型

  userType: null, //商机类型

  offset: null, //筛选网络的条件
  type: null, //筛选春促栅格类型
  offsetCId: null, //网络覆盖率的 选中id
  offsetSort: {
    sortType: null,
    sortStr: null
  }, //网络覆盖率的sort 包含 sortType、sortStr

  perspective: 1, // 经纬度分析：1，方位角分析：2
  stateType: 1, //网络类型 1全部
  longitudeType: 1, //经纬度偏差 1全部
  azimuthType: 1, //方位角偏差 1全部
  cId: null, //经纬度/ 方位角 关键字段id，
  lonAndAzSortType: null, //经纬度方位角的 排序
  mapId: 1, // 平面图：1， 卫星图：2

  //是否竞对
  compare: false,
  //开启竞对 的列表
  rMnc: null, //右侧对比运营商
  rMonth: null, //右侧对比月份

  // 图层
  allBoundaryType: null, //绘制多边界的type (无点击事件);
  communityList: [], //小区工参的 多选列表；
  customList: [], //自定义参数的列表；

  // 筛选项所选列表
  mncList: [], // 运营商可选列表
  rMncList: [], //右侧竞对的运营商列表
  networkList: [], //图层列表
  monthList: [], //月份列表
  zoneList: [], //区县列表
  companyList: [], //子公司列表
  networkGridList: [], //网格列表
  microGridList: [], //微格列表
  townList: [], //街道列表

  areaTypeList: [], //场景列表
  offsetList: [], //网络分析列表
  offsetNetList: [], //网络分析栅格场景筛选列表
  // 右侧菜单列表
  lonList: [], //经纬度 列表
  azList: [], //方位角 列表
  offsetCoverageList: [], //网络覆盖率列表
  searchWordList: [], //搜索词列表

  // 右侧筛选列表
  inUseAttrList: [], //正在使用的筛选项的列表
  filterList: [], //筛选列表的 表格
  filterPageNum: 1,
  filterPageSize: 10,
  filterTotal: 1,
  filterSort: {
    sortType: null,
    sortStr: null
  },
  dataSelectList: [], //筛选列表的 筛选项列表

  userLineDetails: null, //用户点击的详情列表
  userLineDetailsLabel: {
    //中文注解
    name: '区域',
    numAll: '用户数量',
    mobileBelongRatio: '移动归属',
    mobileCoverRate: '移动覆盖',
    mobileRatio: '移动常驻',
    unicomBelongRatio: '联通归属',
    unicomCoverRate: '联通覆盖',
    unicomRatio: '联通常驻',
    telecomBelongRatio: '电信归属',
    telecomCoverRate: '电信覆盖',
    telecomRatio: '电信常驻',
    mobileUserRatio: '移动用户占比',
    unicomUserRatio: '联通用户占比',
    telecomUserRatio: '电信用户占比',
    mobileContrastRatio: '移动份额异动比例',
    unicomContrastRatio: '联通份额异动比例',
    telecomContrastRatio: '电信份额异动比例',
    mobileUserDifference: '移动异网用户数差值',
    unicomUserDifference: '电信异网用户数差值',
    telecomUserDifference: '联通异网用户数差值'
  },
  userLineDetailsAdd: [
    //详情列表 展示顺序
    'numAll',
    'mobileRatio',
    'unicomRatio',
    'telecomRatio',
    'mobileBelongRatio',
    'unicomBelongRatio',
    'telecomBelongRatio',
    'mobileCoverRate',
    'unicomCoverRate',
    'telecomCoverRate'
    // 'mobileUserRatio', 'unicomUserRatio', 'telecomUserRatio',
    // 'mobileContrastRatio', 'unicomContrastRatio', 'telecomContrastRatio',
    // 'mobileUserDifference','unicomUserDifference','telecomUserDifference'
  ],
  allAttrList: [
    //完整可显示属性
    'name',
    'numAll',
    'mobileRatio',
    'unicomRatio',
    'telecomRatio',
    'mobileBelongRatio',
    'unicomBelongRatio',
    'telecomBelongRatio',
    'mobileCoverRate',
    'unicomCoverRate',
    'telecomCoverRate'
  ],

  // echarts图表内容
  panelType: '1', //详情里图表的第一行类型选项: 1用户，2网络,1b用户趋势，2b网络趋势
  panelCellType: '0', //详情 图表 的第二行选项: 0全部, 4 4g， 5 5g
  echartsData: [], //echarts 获取的数据
  indicatorType: 0,
  goBackType: 0,
  day: null,
  modalVisible: false,
  gridStatus: false, //栅格数据开关-网络评估
  stateListStatus: true, //数据指标开关-用户分析
  sceneStatus: true, //场景数据开关-用户分析
  dateList: []
}

const mutations = {
  setRouteType(state, data) {
    state.routeType = data
    // // 修改网络制式图层选择列表
    // this.commit('gisForm/setNetworkList');
  },
  setModalVisible(state, data) {
    state.modalVisible = data
  },
  setSceneStatus(state, data) {
    state.sceneStatus = data
  },
  setGridStatus(state, data) {
    state.gridStatus = data
  },
  setStateListStatus(state, data) {
    state.stateListStatus = data
  },
  setRouteAreaType(state, data) {
    // 选择任意值 需清空之前的选项
    let commitStr =
      'gisForm/' +
      (state.routeAreaType == 3
        ? 'setAreaType'
        : state.routeAreaType == 4
        ? 'setUserType'
        : state.routeAreaType == 2
        ? 'setOffset'
        : state.routeAreaType == 5
        ? 'setType'
        : '')
    if (commitStr.length > 8) {
      this.commit(commitStr, null)
    }

    state.routeAreaType = data
  },
  setShowLayer(state, data) {
    if (data) {
      // 设置图层 top
      let windowHeight = window.innerHeight
      let layerBoxHeight = 407
      let leftMenuIconTop = 494
      // if( leftMenuIconTop + layerBoxHeight > windowHeight ) {
      this.commit('gisForm/setLayerBoxTop', windowHeight - layerBoxHeight)
      // }else {
      //   this.commit( 'gisForm/setLayerBoxTop', leftMenuIconTop )
      // }
    }

    state.showLayer = data

    if (!data) {
      // 设置成默认值 重新打开 重新计算
      this.commit('gisForm/setLayerBoxTop', 185)
    }
  },
  setLayerBoxTop(state, data) {
    // console.log( 'setLayerBoxTop', data );
    state.layerBoxTop = data
  },

  setMnc(state, data) {
    state.mnc = data
    // 关闭筛选列表选中
    if (state.userLineId !== null)
      this.commit('gisForm/setUserLineId', { data: null, jumpMap: false })
    // 修改运营商列表
    this.commit('gisForm/setMncList')
    // 修改网络分析列表
    this.commit('gisForm/setOffsetList')
    this.commit('gisForm/setOffsetNetList')
    // 修改完mnc 网络分析列表改变  offset需置空
    this.commit('gisForm/setOffset', null)
    // 查询当前 网格&热力 图层
    console.log('setMnc', data)
    queryBoundary(
      this,
      state.network,
      state.mnc,
      state.ptMonth,
      state.day,
      state.type,
      1
    )
  },
  setNetwork(state, data) {
    state.network = data
    if (state.routeAreaType == 1 && (data == '7+' || data == '6+')) {
      this.commit('gisForm/setCompare', false)
    }
    // 查询当前 网格&热力 图层
    queryBoundary(
      this,
      state.network,
      state.mnc,
      state.ptMonth,
      state.day,
      state.type,
      1
    )
    if (state.compare) {
      queryBoundary(
        this,
        state.network,
        state.rMnc,
        state.rMonth,
        state.day,
        state.type,
        2
      )
    }
  },
  clearData(state) {
    //重置页面清空数据
    state.ptMonth = null
    state.day = null
    state.type = null
  },
  setPtMonth(state, data) {
    state.ptMonth = data
    // 查询当前 网格&热力 图层
    queryBoundary(
      this,
      state.network,
      state.mnc,
      state.ptMonth,
      state.day,
      state.type,
      1
    )
    // 查询当前 经纬度或 方位角图层
    queryLonAndAz(this, state)
    // 查询 当前大栅格
    queryBigGrid(this, state)
    // 查询 当前筛选列表
    this.dispatch('gisForm/changeFilterList', {})
  },
  setZoneId(
    state,
    { data, ifNav = false, flag = false, townId = '全部', getBoundary = false }
  ) {
    let oldData = state.zoneId
    state.zoneId = data
    if (getBoundary) {
      //如果传入getBoundary 代表需要展示区域边界
      getAllBoundary({
        zoneId: data,
        type: 2
      }).then(res => {
        let gisObj = this.state.gisPage.gisObj
        if (res && gisObj) {
          //  有点击效果
          gisObj.unSelectArea()
          gisObj.setArea(res.data)
          // gisObj.locateArea(this.home.userInfoVo.provinceId)
          // gisObj.unSelectArea()
          gisObj.clearBoundary()
        } else if (!res) {
          gisObj.clearArea()
        }
      })
    }
    // this.initLonAndAz()
    // initBoundary()
    // if( data == null ) {
    //   this.commit('gisForm/setNetworkGridId', this.state.home.userInfoVo.cityId);
    // }
    // 获取区县列表
    // if( oldData == null && data == this.state.home.userInfoVo.cityId ) {
    if (oldData == null && data !== null) {
      // zoneId设置成时非null 网格id设置成null
      this.commit('gisForm/setCompanyId', { data: null })
      this.dispatch('gisForm/changeZoneList')
    } else if (data == null && state.companyId == null) {
      this.commit('gisForm/setCompanyId', {
        data: this.state.home.userInfoVo.cityId
      })
    }

    if (data == null || data == this.state.home.userInfoVo.cityId) {
      // 当zoneId设置 成全部或null时 需置空 TownId
      this.commit('gisForm/setTownId', { data: null, ifNav })
      if (
        data == this.state.home.userInfoVo.cityId &&
        this.state.gisPage.gisObj !== null
      ) {
        // 选中本市 跳转回本市
        let item = this.state.gisPage.dictionary.find(
          v => v.id == this.state.home.userInfoVo.cityId
        )
        setBoundary(item, this.state.gisPage.gisObj)
      }
    } else if (state.zoneList.find(v => v.id == data) != undefined) {
      // 当zoneId 为区县列表中其他值时 则设置 街道为全部 调用获取街道列表
      if (state.routeAreaType == 5) {
        this.commit('gisForm/setTownId', { data: townId })
        if (townId == '全部') {
          this.commit('gisForm/setIndicator', 0)
          this.commit('gisForm/setModalVisible', false)
        }
      } else {
        this.commit('gisForm/setTownId', { data: '全部', ifNav })
      }
      this.dispatch('gisForm/changeTownList', data)
    }
    // zoneId 改变会带来townId改动 所以和townId一起的不需要一起调接口(当前筛选列表)
  },
  setTownId(state, { data, ifNav = false, status }) {
    state.townId = data
    if (state.routeAreaType == 5) {
      if (data == '全部' || !data) {
        this.commit('gisForm/setNetwork', null)
        this.commit('gisForm/setCompare', false)
        this.commit('gisForm/setHolidayType', 11)
      } else {
        if (state.dateList && state.dateList.length) {
          const day = state.dateList ? state.dateList[0].day : null
          this.commit('gisForm/setDay', day)
        }
        window.console.log(data, 'data')
        this.commit('gisForm/setIndicator', data)
        this.commit('gisForm/setAllBoundaryType', null)
      }
    }
    if (state.zoneId !== null) {
      // 查询 当前筛选列表
      this.dispatch('gisForm/changeFilterList', { ifNav })
      if (state.routeAreaType == 5) {
        if (this.state.gisPage.gisObj) {
          this.state.gisPage.gisObj.clearArea()
        }
      } else {
        // 查询当前 网格&热力 图层
        queryBoundary(
          this,
          state.network,
          state.mnc,
          state.ptMonth,
          state.day,
          state.type,
          1
        )
        if (state.compare) {
          queryBoundary(
            this,
            state.network,
            state.rMnc,
            state.rMonth,
            state.day,
            state.type,
            2
          )
        }
      }
      // 绘制多边界
      if (state.areaType !== null) queryAllBoundaryHaveClick(this, state)
      // 筛选项跳转
      let label = state.townId == '全部' ? 'zoneId' : 'townId'
      if (!ifNav) queryLocateArea(this, state, label, state[label])
    }
  },

  setCompanyId(state, { data, ifNav = false }) {
    let oldData = state.companyId
    state.companyId = data
    console.log(state, oldData)

    // 获取网格列表
    // if( oldData == null && data == this.state.home.userInfoVo.cityId ) {
    if (oldData == null && data !== null) {
      // networkGridId设置非null时 zoneId设置成null，
      this.commit('gisForm/setZoneId', { data: null })
      this.dispatch('gisForm/changeNetworkGridList', data)
    } else if (data == null && state.zoneId == null) {
      this.commit('gisForm/setZoneId', {
        data: this.state.home.userInfoVo.cityId
      })
    }
    if (data == null || data == this.state.home.userInfoVo.cityId) {
      // 当networkGridId设置 成全部或null时 需置空 microGridId
      this.commit('gisForm/setNetworkGridId', { data: null, ifNav })
      if (
        data == this.state.home.userInfoVo.cityId &&
        this.state.gisPage.gisObj !== null
      ) {
        // 选中本市 跳转回本市
        let item = this.state.gisPage.dictionary.find(
          v => v.id == this.state.home.userInfoVo.cityId
        )
        setBoundary(item, this.state.gisPage.gisObj)
      }
    } else if (state.companyList.find(v => v.id == data) != undefined) {
      window.console.log(22222)
      // 当zoneId 为区县列表中其他值时 则设置 微格为全部 调用获取微格列表
      this.commit('gisForm/setNetworkGridId', { data: '全部', ifNav })
      this.dispatch('gisForm/changeNetworkGridList', data)
    }
    this.dispatch('gisForm/changeFilterList', { ifNav }) //-t
    // networkGridId 改变会带来microGridId改动 所以和microGridId一起的不需要一起调接口(当前筛选列表)
  },

  setNetworkGridId(state, { data, ifNav = false }) {
    window.console.log(data, ifNav, 'ifNav==', state)
    let oldData = state.networkGridId
    state.networkGridId = data
    console.log(state.networkGridList.find(v => v.id == data) != undefined)
    if (state.companyId == null || data == null) {
      this.commit('gisForm/setMicroGridId', { data: null, ifNav })
    } else {
      if (data == '全部') {
        // 当networkGridId设置 成全部或null时 需置空 microGridId
        this.commit('gisForm/setMicroGridId', { data: null, ifNav })
        // this.dispatch('gisForm/changeFilterList', { ifNav })
        queryBoundary(
          this,
          state.network,
          state.mnc,
          state.ptMonth,
          state.day,
          state.type,
          1
        )
        if (state.compare) {
          queryBoundary(
            this,
            state.network,
            state.rMnc,
            state.rMonth,
            state.day,
            state.type,
            2
          )
        }
        // 绘制多边界
        if (state.areaType !== null) queryAllBoundaryHaveClick(this, state)
        // 筛选项跳转
        let label =
          state.networkGridId == '全部' || state.networkGridId == null
            ? 'companyId'
            : 'networkGridId'
        if (!ifNav) queryLocateArea(this, state, label, state[label])
      } else if (state.networkGridList.find(v => v.id == data) != undefined) {
        // 当zoneId 为区县列表中其他值时 则设置 微格为全部 调用获取微格列表
        this.commit('gisForm/setMicroGridId', { data: '全部', ifNav })
        this.dispatch('gisForm/changeMicroGridList', data)
      }
    }
    // if (state.companyId !== null) {
    //   if (state.networkGridId != '全部' && state.networkGridId != null) {
    //     this.commit('gisForm/setMicroGridId', { data: '全部', ifNav });
    //     this.dispatch( 'gisForm/changeMicroGridList', data )
    //   } else {
    //    this.commit('gisForm/setMicroGridId', { data: null, ifNav });
    //   //   this.dispatch('gisForm/changeFilterList', { ifNav })
    //   //   queryBoundary(this, state.network, state.mnc, state.ptMonth, 1);
    //   //   if (state.compare) {
    //   //     queryBoundary(this, state.network, state.rMnc, state.rMonth, 2);
    //   //   }
    //   //   // 绘制多边界
    //   //   if (state.areaType !== null) queryAllBoundaryHaveClick(this, state)
    //   //   // 筛选项跳转
    //   //   let label = state.networkGridId == '全部' ? 'companyId' : 'networkGridId';
    //   //   if (!ifNav) queryLocateArea(this, state, label, state[label])
    //   }
    // }
    // networkGridId 改变会带来microGridId改动 所以和microGridId一起的不需要一起调接口(当前筛选列表)
  },
  setMicroGridId(state, { data, ifNav = false }) {
    state.microGridId = data
    // 查询 当前筛选列表
    window.console.log('microGridId', data)
    if (state.networkGridId !== null && state.microGridId != null) {
      this.dispatch('gisForm/changeFilterList', { ifNav })
      // 查询当前 网格&热力 图层

      queryBoundary(
        this,
        state.network,
        state.mnc,
        state.ptMonth,
        state.day,
        state.type,
        1
      )
      if (state.compare) {
        queryBoundary(
          this,
          state.network,
          state.rMnc,
          state.rMonth,
          state.day,
          state.type,
          2
        )
      }
      // 绘制多边界
      if (state.areaType !== null) queryAllBoundaryHaveClick(this, state)
      // 筛选项跳转
      let label = state.microGridId == '全部' ? 'networkGridId' : 'microGridId'
      if (!ifNav) queryLocateArea(this, state, label, state[label])
    }
  },
  setKeyWord(state, { keyWord, setSearchListToId = null }) {
    console.log('setKeyWord', setSearchListToId)
    // // 使用搜索时 关闭覆盖率列表
    // if( keyWord && state.offset  ) this.commit('gisForm/setOffset', null);

    // 清除选中id, 当搜索列表从有值到没值的时候 需要清空选中id
    if (!keyWord && state.keyWord && state.userLineId)
      this.commit('gisForm/setUserLineId', { data: null, jumpMap: false })

    state.keyWord = keyWord

    // 请求 搜索词列表
    if (keyWord)
      this.dispatch('gisForm/changeSearchWordList', {
        keyWord,
        setSearchListToId
      })
  },
  setUserLineId(
    state,
    {
      data,
      jumpMap,
      ifSearch = false,
      ifNav = false,
      navItem = null,
      jumpType = false
    }
  ) {
    state.userLineId = data
    if (state.routeAreaType == 5) {
      const count = state.townId
        ? state.indicatorType
          ? null
          : state.townId == '全部'
          ? 2
          : null
        : 2
      const BoundType =
        state.zoneId == this.state.home.userInfoVo.cityId ? null : count
      this.dispatch('gisForm/setTypeHoliday', state.type || 11)
      // this.commit('gisForm/setAllBoundaryType', BoundType)
    }
    if (
      this.state.gisPage.gisObj !== null &&
      this.state.gisPage.iframeUrl == 'index' &&
      data !== null
    ) {
      if (jumpMap) {
        let typeIdList = [
          'zoneId',
          'townId',
          'areaId',
          'networkGridId',
          'microGridId'
        ]

        // 跳转到当前列表点
        if (ifSearch) {
          let checkItem = state.searchWordList.find(
            v => v.typeId == state.userLineId
          )
          let label = checkItem && typeIdList[checkItem.type - 1]
          // 搜索列表跳转
          queryLocateArea(this, state, label, state.userLineId)
          // 获取详情列表
          this.dispatch('gisForm/changeUserLineDetails', {
            label,
            value: state.userLineId,
            type: checkItem.type
          })
        } else if (ifNav) {
          // 导航跳转
          let type = typeIdList.findIndex(v => v == navItem.label) + 1
          // 获取详情列表
          this.dispatch('gisForm/changeUserLineDetails', {
            label: navItem.label,
            value: state.userLineId,
            type
          })
          // 搜索列表跳转
          if (navItem.id != this.state.home.userInfoVo.cityId) {
            // 不等于当前市id 才跳转
            queryLocateArea(this, state, navItem.label, state.userLineId)
          }
        } else {
          const flag = jumpType && state.routeAreaType == 5
          // 筛选项列表跳转
          if (state.areaType === null && !flag) {
            // 非场景跳转
            let label =
              state.userLineDetails !== null &&
              typeIdList[state.userLineDetails.type - 1]
            queryLocateArea(this, state, label, state.userLineId)
          } else {
            // 场景跳转
            locateArea(state.userLineId, this.state.gisPage.gisObj)
          }
          if (state.routeAreaType == 5) {
            this.state.gisPage.gisObj.clearArea()
          }
        }
      } else {
        // 地图点跳转到选中id页 只针对场景 (由于有分页 不好跳转 功能暂停开发)
        // 设置 地图点击点的 详情数据获取
        this.dispatch('gisForm/changeUserLineDetails', {
          label: 'areaId',
          value: state.userLineId,
          type: 3
        })
      }
    }

    // // 取消选中id 需要清除绘制区域跳转到当前城市
    // if( data === null  ) {
    //   if( state.areaType !== null ) {
    //     locateArea(null, this.state.gisPage.gisObj)

    //   }else {
    //     //  取消普通选点
    //     clearBoundary( this.state.gisPage.gisObj );
    //   }

    // }
  },

  setUserAnalysisType(state, data) {
    console.log(state, data)
    state.userAnalysisType = data
    state.network = data
    queryBoundary(
      this,
      state.network,
      state.mnc,
      state.ptMonth,
      state.day,
      state.type,
      1
    )
    if (state.compare) {
      queryBoundary(
        this,
        state.network,
        state.rMnc,
        state.rMonth,
        state.day,
        state.type,
        2
      )
    }
  },
  setAreaType(state, data) {
    state.areaType = data
    // 查询 当前筛选列表
    this.dispatch('gisForm/changeFilterList', {})
    // 绘制多边界
    queryAllBoundaryHaveClick(this, state)
  },
  setUserType(state, data) {
    state.userType = data
    // 查询 当前筛选列表
    this.dispatch('gisForm/changeFilterList', {})
  },
  setOffset(state, data) {
    // // 使用覆盖率关闭搜索词列表
    // if( data !== null && state.keyWord ) this.commit('gisForm/setKeyWord', null);

    state.offset = data
    // 需要开启大栅格
    queryBigGrid(this, state)
    //切换网络分析 需切换右侧运营商列表
    this.commit('gisForm/setRMncList')
  },
  setType(state, data) {
    state.type = data
    // 需要开启大栅格
    // queryBigGrid(this, state)
    queryBoundary(
      this,
      state.network,
      state.mnc,
      state.ptMonth,
      state.day,
      state.type,
      1
    )

    this.dispatch('gisForm/setTypeHoliday', data)
    if (state.dateList && state.dateList.length) {
      const day = state.dateList ? state.dateList[0].day : null
      this.commit('gisForm/setDay', day)
    }
    if (data == 11 || data == 13) {
      this.commit('gisForm/setCompare', false)
    }
  },
  setOffsetCId(state, { data, jumpMap }) {
    console.log('setOffsetCId', data)
    state.offsetCId = data

    if (
      this.state.gisPage.gisObj !== null &&
      this.state.gisPage.iframeUrl == 'index' &&
      data !== null
    ) {
      if (jumpMap) {
        // 跳转到当前列表点
        zoomToBigGrid(data, this.state.gisPage.gisObj)
      } else {
        // 地图点跳转到选中id页 组件内监控判断
      }
    }
  },
  setOffsetSort(state, data) {
    state.offsetSort = data
    // 查询大栅格数据
    queryBigGrid(this, state)
  },

  setPerspective(state, data) {
    state.perspective = data
    let iframeUrl = data == 1 ? 'sitePositionOffset' : 'cellAzOffset'
    this.commit('gisPage/setIframeUrl', iframeUrl)
  },
  setStateType(state, data) {
    state.stateType = data
    // 查询当前 经纬度或 方位角图层
    queryLonAndAz(this, state)
  },
  setLongitudeType(state, data) {
    state.longitudeType = data
    // 查询当前 经纬度或 方位角图层
    queryLonAndAz(this, state)
  },
  setAzimuthType(state, data) {
    state.azimuthType = data
    // 查询当前 经纬度或 方位角图层
    queryLonAndAz(this, state)
  },
  setCId(state, { data, jumpMap }) {
    console.log('setCId', data)
    state.cId = data

    if (
      this.state.gisPage.gisObj !== null &&
      this.state.gisPage.iframeUrl !== 'index' &&
      data !== null
    ) {
      if (jumpMap) {
        // 跳转到当前列表点
        getLocateCell(state.perspective, data, this.state.gisPage.gisObj)
      } else {
        // 地图点跳转到选中id页 组件内监控判断
      }
    }
  },
  setLonAndAzSortType(state, data) {
    state.lonAndAzSortType = data
    // 查询当前 经纬度或 方位角图层
    queryLonAndAz(this, state)
  },

  setMapId(state, data) {
    state.mapId = data
    // 设置完需要 gis跟换图层;
    if (this.state.gisPage.gisObj !== null)
      changeMap(data, this.state.gisPage.gisObj)
  },
  setCompare(state, data) {
    console.log('setCompare', data)
    state.compare = data
    // 如果 对比为true 需要 把左侧月份值赋给右侧
    if (data) this.commit('gisForm/setRMonth', state.ptMonth)
    // 设置完 gis开启对比或关闭
    if (
      this.state.gisPage.gisObj !== null &&
      this.state.gisPage.iframeUrl === 'index'
    )
      compareFn(data, this.state.gisPage.gisObj)
  },
  setRMnc(state, data) {
    state.rMnc = data
    // 查询当前 网格&热力 图层

    if (state.compare)
      queryBoundary(
        this,
        state.network,
        state.rMnc,
        state.rMonth,
        state.day,
        state.type,
        2
      )
  },
  setRMonth(state, data) {
    state.rMonth = data
    // 查询当前 网格&热力 图层
    console.log('setRMonth', data)

    if (state.compare)
      queryBoundary(
        this,
        state.network,
        state.rMnc,
        state.rMonth,
        state.day,
        state.type,
        2
      )
  },

  setAllBoundaryType(state, data) {
    state.allBoundaryType = data
    if (this.state.gisPage.gisObj)
      getAllBoundaryNoClick(
        this.state.home.userInfoVo.cityId,
        data,
        this.state.gisPage.gisObj
      )
  },
  setCommunityList(state, data) {
    console.log('setCommunityList', data)
    // 不重复的数组
    let noRepeatList = getNoRepeatList(state.communityList, data)
    // 只存在一个一个选的情况下的 判断 （全选全不选需重新设计）
    if (data.length > state.communityList.length) {
      // 增加一个
      queryCommunity(noRepeatList, this)
    } else {
      // 减少一个
      let delStatus = noRepeatList[0].split('+')[1] == 4 ? 1 : 2
      delGisCommunity(delStatus, this.state.gisPage.gisObj)
    }

    state.communityList = data
  },
  setCustomList(state, data) {
    console.log('setCustomList', data)
    // 不重复的数组
    let noRepeatList = getNoRepeatList(state.customList, data)
    // 只存在一个一个选的情况下的 判断 （全选全不选需重新设计）
    if (data.length > state.communityList.length) {
      // 增加一个
      queryCustom(noRepeatList, 'show', this)
    } else {
      // 减少一个
      queryCustom(noRepeatList, 'hide', this)
    }
    state.customList = data
  },

  setMncList(state, data) {
    // console.log( state,  data, this );
    const mnc = state.mnc
    const y = { label: '移动', value: '0' },
      l = { label: '联通', value: '1' },
      d = { label: '电信', value: '11' }
    let arr = []
    if (mnc == y.value) {
      arr = [l, d, y]
    } else if (mnc == l.value) {
      arr = [d, y, l]
    } else {
      arr = [y, l, d]
    }

    state.mncList = arr
  },
  setRMncList(state, data) {
    // console.log( state,  data, this );
    // alert('设置右侧运营商列表')
    const mnc = state.mnc
    const y = { label: '移动', value: '0' },
      l = { label: '联通', value: '1' },
      d = { label: '电信', value: '11' }
    let arr = []

    if (state.offset == null) {
      if (mnc == y.value) {
        arr = [l, d, y]
      } else if (mnc == l.value) {
        arr = [d, y, l]
      } else {
        arr = [y, l, d]
      }
    } else {
      let offsetItem = state.offsetList.find(v => v.value == state.offset)

      if (offsetItem.label.length == 4) {
        let mncStr = offsetItem.label.substring(2, 4)
        if (mncStr == y.label) {
          arr = [y]
        } else if (mncStr == l.label) {
          arr = [l]
        } else {
          arr = [d]
        }
      } else {
        let mncStr1 = offsetItem.label.substring(2, 4)
        let mncStr2 = offsetItem.label.substring(5)

        if (mncStr1 !== y.label && mncStr2 !== y.label) {
          arr = [l, d]
        } else if (mncStr1 !== l.label && mncStr2 !== l.label) {
          arr = [y, d]
        } else {
          arr = [y, l]
        }
      }
    }

    // 列表改变需切换右侧运营商为数组第一项,除非offset为空的情况下
    if (state.offset !== null) this.commit('gisForm/setRMnc', arr[0].value)

    state.rMncList = arr
  },

  setMonthList(state, data) {
    let d = new Date()
    let y = d.getFullYear()
    let m = d.getMonth()
    let arr = [],
      arr1 = [],
      arr2 = []
    for (let i = 1; i <= m; i++) {
      let str = y + '.' + i
      let v = y + '' + i
      if (i < 10) {
        str = y + '.0' + i
        v = y + '0' + i
      }
      arr1.push({ label: str, value: Number(v) })
    }
    if (arr1.length < 12) {
      for (let i = 12; i > arr1.length; i--) {
        let str = y - 1 + '.' + i
        let v = y - 1 + '' + i
        if (i < 10) {
          str = y - 1 + '.0' + i
          v = y - 1 + '0' + i
        }
        arr2.push({ label: str, value: Number(v) })
      }
    }
    arr1 = arr1.reverse()
    arr = arr1.concat(arr2)

    // 如果月份值为null 不存在的情况 会给默认值
    if (!state.ptMonth) {
      if (d.getDate() <= 7) {
        this.commit('gisForm/setPtMonth', arr[1]['value'])
      } else {
        this.commit('gisForm/setPtMonth', arr[0]['value'])
      }
    }
    state.monthList = arr
  },

  // setNetworkList(state, data) {
  //   let list = [
  //     // 用户
  //     [ { label: null, value: null }, { label:'4G', value: '3+4' }, { label:'5G', value: '3+5' }, { label:'4G漫入', value: '5+4' }, { label:'5G漫入', value: '5+5' } ],
  //     // 网络
  //     [ { label: null, value: null }, { label:'4G覆盖', value: '1+4' }, { label:'5G覆盖', value: '1+5' }, { label:'4G质量', value: '4+4' }, { label:'5G质量', value: '4+5' } ]
  //   ]

  //   state.networkList = state.routeType ? list[ state.routeType - 1 ]: [];

  //   // 修改当前网络
  //   if( state.routeType && state.networkList.find( v => v.value == state.network ) == undefined  ) {
  //     this.commit('gisForm/setNetwork', state.networkList[1].value )
  //   }
  // },

  setZoneList(state, data) {
    state.zoneList = data
  },
  setIndicator(state, data) {
    state.indicatorType = data
  },
  setGoBackType(state, data) {
    state.goBackType = data
  },
  setDay(state, data) {
    state.day = data
    // 播放热力图
    this.commit('gisForm/setNetwork', '3+')
  },
  setDayListDate(state, data) {
    state.dateList = data
  },
  setHolidayType(state, data) {
    state.type = data
  },
  setTownList(state, data) {
    state.townList = data
  },
  setCompanyList(state, data) {
    state.companyList = data
  },
  setNetworkGridList(state, data) {
    state.networkGridList = data
  },
  setMicroGridList(state, data) {
    state.microGridList = data
  },
  setAreaTypeList(state, data) {
    state.areaTypeList = data
  },
  setOffsetList(state, data) {
    // 当前的是c
    let mnc = state.mnc
    let a, b, c, a1, b1, c1
    if (mnc == 0) {
      a = '电信'
      b = '联通'
      c = '移动' //弱于电信 弱于联通 弱于电信和联通
      a1 = '11'
      b1 = '1'
      c1 = '0'
    } else if (mnc == 1) {
      a = '移动'
      b = '电信'
      c = '联通' //弱于移动 弱于电信 弱于移动和电信
      a1 = '0'
      b1 = '11'
      c1 = '1'
    } else {
      a = '移动'
      b = '联通'
      c = '电信' //弱于移动 弱于联通 弱于移动和联通
      a1 = '0'
      b1 = '1'
      c1 = '11'
    }
    let obj0 = { label: null, value: null }
    const obj1 = { label: '弱于' + a, value: c1 + '-' + a1 }
    const obj2 = { label: '弱于' + b, value: c1 + '-' + b1 }
    const obj3 = { label: '弱于' + a + '&' + b, value: mnc }
    // const obj4={label:'弱于'+c,value:c1+'-'+c1}
    const arr = [obj0, obj1, obj2, obj3]
    state.offsetList = arr
  },
  setOffsetNetList(state, data) {
    // 当前的是c
    let mnc = state.mnc
    let a, b, c, a1, b1, c1
    if (mnc == 0) {
      a = '电信'
      b = '联通'
      c = '移动' //弱于电信 弱于联通 弱于电信和联通
      a1 = '11'
      b1 = '1'
      c1 = '0'
    } else if (mnc == 1) {
      a = '移动'
      b = '电信'
      c = '联通' //弱于移动 弱于电信 弱于移动和电信
      a1 = '0'
      b1 = '11'
      c1 = '1'
    } else {
      a = '移动'
      b = '联通'
      c = '电信' //弱于移动 弱于联通 弱于移动和联通
      a1 = '0'
      b1 = '1'
      c1 = '11'
    }
    let obj0 = { label: null, value: null }
    const obj1 = { label: '占比高于' + a, value: c1 + '-' + a1 }
    const obj2 = { label: '占比高于' + b, value: c1 + '-' + b1 }
    const obj3 = { label: '占比高于' + a + '及' + b, value: mnc }
    // const obj4={label:'弱于'+c,value:c1+'-'+c1}
    const arr = [obj0, obj1, obj2, obj3]
    state.offsetNetList = arr
  },

  setLonList(state, data) {
    // console.log( 'setLonList', data );
    state.lonList = data
  },
  setAzList(state, data) {
    // console.log( 'setAzList', data );
    state.azList = data
  },

  setOffsetCoverageList(state, data) {
    // console.log( 'setOffsetCoverageList', data );
    state.offsetCoverageList = data
  },
  setSearchWordList(state, { data, setSearchListToId }) {
    console.log('setSearchWordList', data, setSearchListToId)
    state.searchWordList = data
    // 设置从报告页面跳转过来的id
    if (setSearchListToId)
      this.commit('gisForm/setUserLineId', {
        data: setSearchListToId,
        jumpMap: true,
        ifSearch: true
      })
  },
  setInUseAttrList(state, data) {
    // console.log( 'setInUseAttrList', data );
    state.inUseAttrList = data
  },

  setFilterList(state, { data, ifNav = false }) {
    // console.log( 'setFilterList', data );
    state.filterList = data

    // 当前筛选属性表发生变化 需清空选中id -t
    // if (state.userLineId && !ifNav) {
    //   this.commit('gisForm/setUserLineId', { data: null, jumpMap: false })
    // }
  },
  setFilterPageNum(state, data) {
    // console.log( 'setFilterPageNum', data );
    state.filterPageNum = data
    // 查询 当前筛选列表
    this.dispatch('gisForm/changeFilterList', {})
  },
  setFilterPageSize(state, data) {
    // console.log( 'setFilterPageSize', data );
    state.filterPageSize = data
    // 查询 当前筛选列表
    this.dispatch('gisForm/changeFilterList', {})
  },
  setFilterTotal(state, data) {
    // console.log( 'setFilterTotal', data );
    state.filterTotal = data
  },
  setFilterSort(state, data) {
    // console.log( 'setFilterSort', data );
    state.filterSort = data
    // 查询 当前筛选列表
    this.dispatch('gisForm/changeFilterList', {})
  },
  setDataSelectList(state, data) {
    console.log('setDataSelectList', data)
    state.dataSelectList = data

    // 查询 当前筛选列表
    this.dispatch('gisForm/changeFilterList', {})
  },

  setUserLineDetails(state, data) {
    console.log('setUserLineDetails', data)
    state.panelType = '1'
    state.panelCellType = 0
    state.userLineDetails = data
    if (data) {
      this.dispatch('gisForm/changeEchartsData')
    }
  },
  setIndicatorType(state, data) {
    this.dispatch('gisForm/setIndicatorData', data)
  },
  setBackType(state, data) {
    this.dispatch('gisForm/setGoBackTypeData', data)
  },
  setDayDis(state, data) {
    this.dispatch('gisForm/setDayData', data)
  },
  setDayList(state, data) {
    this.dispatch('gisForm/setDateList', data)
  },
  setModalFlag(state, data) {
    this.dispatch('gisForm/setVisibleFlag', data)
  },
  setPanelType(state, data) {
    console.log('setPanelType', data, state)
    let oldData = state.panelType
    state.panelType = data
    // 当选中id 不为空且 panelType 不是同类型的 值 则调用 获取echarts数据
    if (state.userLineId != null && parseInt(oldData) != parseInt(data)) {
      this.dispatch('gisForm/changeEchartsData')
    } else if (state.userLineId != null && state.userType > 3) {
      this.dispatch('gisForm/changeEchartsData')
    } else if (state.routeAreaType == 5) {
      this.dispatch('gisForm/changeEchartsData')
    }
  },
  setPanelCellType(state, { data, changeEchartsData = true }) {
    console.log('setPanelCellType', data)
    state.panelCellType = data
    if (state.userLineId != null && changeEchartsData) {
      this.dispatch('gisForm/changeEchartsData')
    } else if (state.routeAreaType == 5) {
      this.dispatch('gisForm/changeEchartsData')
    }
  },
  setEchartsData(state, data) {
    console.log('setEchartsData', data)
    state.echartsData = data
  }
}

const actions = {
  setIndicatorData({ commit, state }, data) {
    commit('setIndicator', data)
  },
  setGoBackTypeData({ commit, state }, data) {
    commit('setGoBackType', data)
  },
  setDayData({ commit, state }, data) {
    commit('setDay', data)
  },
  setDateList({ commit, state }, data) {
    commit('setDayListDate', data)
  },
  setVisibleFlag({ commit, state }, data) {
    commit('setModalVisible', data)
  },
  setTypeHoliday({ commit, state }, data) {
    commit('setHolidayType', data)
  },
  changeZoneList({ commit }, data) {
    let distinctId = this.state.home.userInfoVo.distinctId
    let authorities = this.state.home.userInfoVo.authorities
    api
      .getZone({
        cityId: this.state.home.userInfoVo.cityId
      })
      .then(res => {
        let list = []
        if (
          authorities.indexOf('zone-sort') !== -1 &&
          authorities.indexOf('net-grid-sort') !== -1
        ) {
          list.push({ name: '不限', id: null })
        }
        let distinctIdList = distinctId ? distinctId.split(',') : []
        if (res.data.length !== 0) {
          // 根据权限显示相应列表
          if (distinctIdList.length == 0) {
            list = list.concat(res.data)
          } else {
            list.push({ name: '全部', id: this.state.home.userInfoVo.cityId })
            res.data.forEach(item => {
              if (distinctIdList.includes(item.id)) {
                list.push(item)
              }
            })
          }
        }
        commit('setZoneList', list)
      })
  },
  changeTownList({ commit }, zoneId) {
    let params = {
      zoneId,
      cityId: this.state.home.userInfoVo.cityId
    }
    api.getTownByZoneId(params).then(res => {
      if (res.code === 1) {
        let townList = [{ name: '全部', id: '全部' }]
        if (res.data.length !== 0) {
          townList = townList.concat(res.data)
        }
        commit('setTownList', townList)
      }
    })
  },
  changeCompanyList({ commit }, companyId) {
    let distinctId = this.state.home.userInfoVo.distinctId
    let authorities = this.state.home.userInfoVo.authorities
    api
      .getNetworkGridByCity({
        // companyName:this.state.companyName,
        cityId: this.state.home.userInfoVo.cityId
      })
      .then(res => {
        console.log(res)
        let list = []
        if (
          authorities.indexOf('zone-sort') !== -1 &&
          authorities.indexOf('net-grid-sort') !== -1
        ) {
          list.push({ name: '不限', id: null })
        }
        let distinctIdList = distinctId ? distinctId.split(',') : []
        if (res.data.length !== 0) {
          // 根据权限显示相应列表
          if (distinctIdList.length == 0) {
            list = list.concat(res.data)
          } else {
            list.push({ name: '全部', id: this.state.home.userInfoVo.cityId })
            res.data.forEach(item => {
              if (distinctIdList.includes(item.id)) {
                list.push(item)
              }
            })
          }
        }
        console.log(list)
        commit('setCompanyList', list)
      })
  },
  changeNetworkGridList({ commit }, data) {
    api
      .getNetworkGridByCity({
        companyId: data,
        cityId: this.state.home.userInfoVo.cityId
      })
      .then(res => {
        if (res.code === 1) {
          let list = [{ name: '全部', id: '全部' }]
          if (res.data.length !== 0) {
            list = list.concat(res.data)
          }
          commit('setNetworkGridList', list)
        }
      })
  },
  changeMicroGridList({ commit }, networkGridId) {
    let params = {
      networkGridId,
      cityId: this.state.home.userInfoVo.cityId
    }
    api.getMicroByCity(params).then(res => {
      if (res.code === 1) {
        let microGridList = [{ name: '全部', id: '全部' }]
        if (res.data.length !== 0) {
          microGridList = microGridList.concat(res.data)
        }
        commit('setMicroGridList', microGridList)
      }
    })
  },

  changeAreaTypeList({ commit }, data) {
    api.getAreaType().then(res => {
      let areaArr = []
      if (res.code == 1) {
        areaArr = res.data
        areaArr.unshift(null)
      } else {
        areaArr.unshift(null)
      }
      commit('setAreaTypeList', areaArr)
    })
  },

  changeSearchWordList({ commit }, { keyWord, setSearchListToId }) {
    console.log('changeSearchWordList', setSearchListToId)
    let typeNameList = ['区县', '街道', '场景', '网格', '微格']
    let typeIdList = [
      'zoneId',
      'townId',
      'areaId',
      'networkGridId',
      'microGridId'
    ]
    let params = {
      keyWord,
      cityId: this.state.home.userInfoVo.cityId
    }
    api.getAllKeyWordsTop10(params).then(res => {
      if (res.code === 1) {
        let searchList = []

        res.data.map(item => {
          searchList.push({
            ...item,
            typeName: typeNameList[item.type - 1],
            typeId: item[typeIdList[item.type - 1]]
          })
        })

        commit('setSearchWordList', { data: searchList, setSearchListToId })
      }
    })
  },

  changeUserLineDetails({ commit }, { label, value, type }) {
    let params = {
      ptMonth: this.state.gisForm.ptMonth,
      pageNum: 1,
      pageSize: 20,
      type,
      cityId: this.state.home.userInfoVo.cityId,
      [label]: value
    }
    getAttributeRespnse(params).then(res => {
      if (res.code === 1) {
        // console.log( res );
        if (res.data == null || res.data.list.length == 0) {
          Message.warning('暂无详情数据')
          commit('setUserLineDetails', null)
        } else {
          commit('setUserLineDetails', res.data.list[0])
        }
      } else {
        Message.warning('暂无详情数据')
        commit('setUserLineDetails', null)
      }
    })
  },

  changeEchartsData({ commit, state }, data) {
    console.log(state, 'state vuex')
    let value = this.state.gisForm.userLineDetails.id //当前项的id
    let typeIdList = [
      'zoneId',
      'townId',
      'areaId',
      'networkGridId',
      'microGridId'
    ]
    let label = typeIdList[this.state.gisForm.userLineDetails.type - 1] //根据type判断

    let type = parseInt(this.state.gisForm.panelType) //判断tab 1 用户 2网络 。。。
    let panelCellType = this.state.gisForm.panelCellType //详情 图表 的第二行选项: 0全部, 4 4g， 5 5g

    let cellType =
      type == 1 && panelCellType != '0'
        ? '0'
        : type == 2 && panelCellType == '0'
        ? '4'
        : panelCellType
    console.log(cellType, 'cellType')
    // 如果值 不同需要提示 更换值 且不可继续调用这个接口
    if (cellType != panelCellType)
      commit('setPanelCellType', { data: cellType, changeEchartsData: false })

    let params = {
      cellType,
      type,
      cityId: this.state.home.userInfoVo.cityId,
      [label]: value
    }
    if (state.userType > 3 && state.panelType == 1) {
      commit('setEchartsData', [state.userLineDetails])
    } else {
      // 集团预警 趋势图
      if (state.userType == 4 && state.panelType == '1b') {
        params.type = 5
      }
      // 漫入预警 趋势图
      if (state.userType == 5 && state.panelType == '1b') {
        params.type = 6
      }
      getDataAnalysis(params).then(res => {
        if (res.code === 1) {
          console.log(res)
          commit('setEchartsData', res.data)
        }
      })
    }
  },
  changeInUseAttrList({ commit }, attributeStr) {
    let params = {
      attributeStr: attributeStr
    }
    saveAccountAttributeTable(params).then(res => {
      if (res.code == 1) {
        console.log(res)
        this.dispatch('gisForm/getInUseAttrList')
      }
    })
  },
  getInUseAttrList({ commit }, data) {
    queryAccountAttributeTable().then(res => {
      if (res.code == 1) {
        console.log(res)
        let list = res.data !== null ? res.data.attributeStr.split(';') : []
        // 去除 只有个一个数据 数组最有一个为空的情况
        console.log(list, list.length, 'list')
        if (list.length > 0 && !list[list.length - 1])
          list.length = list.length - 1
        commit('setInUseAttrList', list)
      }
    })
  },
  changeFilterList({ commit }, { ifNav = false }) {
    let cityId = this.state.home.userInfoVo.cityId
    let {
      zoneId,
      townId,
      networkGridId,
      microGridId,
      areaType,
      userType,
      filterSort,
      filterPageNum,
      filterPageSize,
      dataSelectList,
      allAttrList,
      routeAreaType,
      companyId
    } = this.state.gisForm
    // 查找当前列 所有的筛选项
    let copyList = JSON.parse(JSON.stringify(dataSelectList))
    let currentList = []
    allAttrList
      .filter(x => {
        if (!(this.state.home.userInfoVo.superAccount == 2 && x == 'numAll')) {
          return x
        }
      })
      .forEach(item => {
        let selectItem = copyList.find(v => v.selectName == item)
        if (selectItem) {
          if (
            selectItem.conditionalValueList[1].value == null ||
            selectItem.conditionalValueList[1].condition == null
          ) {
            selectItem.conditionalValueList = [
              selectItem.conditionalValueList[0]
            ]
          }
          currentList.push(selectItem)
        }
      })
    let baseParams = {
      ptMonth: this.state.gisForm.ptMonth,
      pageNum: filterPageNum,
      pageSize: filterPageSize,
      cityId,
      sortType: filterSort.sortType,
      sortStr: filterSort.sortStr,
      dataSelectList: currentList
    }
    if (zoneId == null && companyId !== null) {
      baseParams.companyId = companyId
      baseParams.networkGridId = networkGridId
      baseParams.microGridId = microGridId
    } else {
      baseParams.zoneId = zoneId
      baseParams.townId = townId
    }
    if (userType !== null) {
      // 调用商机接口
      let params = {
        ...baseParams,
        userType
      }
      getBusinessRespnse(params).then(res => {
        if (res.code == 1) {
          commit('setFilterTotal', res.data.total)
          if (res.data.lastPage < filterPageNum) {
            commit('setFilterPageNum', res.data.lastPage)
          } else {
            commit('setFilterList', { data: res.data.list, ifNav })
          }
        }
      })
    } else {
      // 调用普通接口
      let type = 1
      let params = {}
      if (baseParams.zoneId) {
        if (areaType != null || (townId != '全部' && townId != null)) {
          type = routeAreaType == 5 ? 2 : 3
        } else if (zoneId != '全部' && zoneId != cityId) {
          type = 2
        }
        params = {
          ...baseParams,
          type,
          zoneId: type == 1 ? null : zoneId,
          townId:
            type == 3 && townId != '全部' && townId != null ? townId : null,
          areaType: type == 3 ? areaType : null
        }
      } else {
        console.log(networkGridId, microGridId)
        type = 6
        if (
          areaType != null ||
          (microGridId != '全部' && microGridId != null)
        ) {
          type = routeAreaType == 5 ? 2 : 3
        } else if (networkGridId != '全部' && companyId != cityId) {
          type = 5
        } else if (networkGridId != null) {
          type = 4
        }
        params = {
          ...baseParams,
          type,
          companyId: companyId,
          networkGridId: type == 4 ? null : networkGridId,
          microGridId:
            type == 3 && microGridId != '全部' && microGridId != null
              ? microGridId
              : null,
          areaType: type == 3 ? areaType : null
        }
      }
      getAttributeRespnse(params).then(res => {
        if (res.code === 1) {
          commit('setFilterTotal', res.data.total)
          if (res.data.lastPage < filterPageNum) {
            commit('setFilterPageNum', res.data.lastPage)
          } else {
            commit('setFilterList', { data: res.data.list, ifNav })
          }
        }
      })
    }
  },

  // 初始化加载调用  查询 网格&热力 图层
  initBoundary() {
    //------
    const { routeAreaType, network, mnc, ptMonth, day, type, offsetList } =
      this.state.gisForm
    if (routeAreaType != 5) {
      queryBoundary(this, network, mnc, ptMonth, day, type, 1)
    }
    if (routeAreaType == 1) {
      this.commit('gisForm/setNetwork', '3+') //-t 默认选中所有用户
    } else if (routeAreaType == 2) {
      let offset = offsetList && offsetList.find(item => item.value)
      this.commit('gisForm/setNetwork', '1+4') //-t 默认选中4g网络覆盖
      this.commit('gisForm/setOffset', offset.value) //-t 默认选中4g网络覆盖
      this.commit('gisForm/setStateListStatus', false)
    } else {
      this.commit('gisForm/setNetwork', null)
    }

    const allBoundaryType =
      routeAreaType == 5 ? 2 : this.state.gisForm.allBoundaryType
    // 加载绘制多边界的方法
    if (this.state.gisPage.gisObj)
      getAllBoundaryNoClick(
        this.state.home.userInfoVo.cityId,
        allBoundaryType,
        this.state.gisPage.gisObj,
        routeAreaType
      )
    // 遍历 小区工参 调用方法
    queryCommunity(this.state.gisForm.communityList, this)
    // 遍历 车站营业厅
    queryCustom(this.state.gisForm.customList, 'show', this)
  },
  // 初始化加载调用  查询 经纬度 或方位角图层
  initLonAndAz() {
    queryLonAndAz(this, this.state.gisForm)
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}
